#include "Task.h"
#include "ThreadPool.h"
#include <cstdlib>
#include <iostream>
#include <memory>
using namespace std;

class MyTask
    : public Task
{
public:
    void process() override
    {
        srand(time(NULL));
        int num = rand() % 100;
        cout << ">>MyTask is processing: " << num << endl;
    }
};

void test()
{
    unique_ptr<Task> ptask(new MyTask());

    ThreadPool pool(4, 10);
    // 启动线程
    pool.start();

    int cnt = 20;
    while (cnt--)
    {
        pool.addTask(ptask.get()); // 生产者：产生任务
        cout << "cnt = " << cnt << endl;
    }

    // 停止线程池
    pool.stop();
}

int main()
{
    test();
    return 0;
}